var e = require;
var t = module;
var n = exports;
var p =
        (this && this.__assign) ||
        function () {
            return (p =
                Object.assign ||
                function (e) {
                    for (var t, n = 1, o = arguments.length; n < o; n++)
                        for (var i in (t = arguments[n])) Object.prototype.hasOwnProperty.call(t, i) && (e[i] = t[i]);
                    return e;
                }).apply(this, arguments);
        },
    o =
        (this && this.__awaiter) ||
        function (e, a, s, c) {
            return new (s = s || Promise)(function (n, t) {
                function o(e) {
                    try {
                        r(c.next(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function i(e) {
                    try {
                        r(c.throw(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function r(e) {
                    var t;
                    e.done
                        ? n(e.value)
                        : ((t = e.value) instanceof s
                              ? t
                              : new s(function (e) {
                                    e(t);
                                })
                          ).then(o, i);
                }
                r((c = c.apply(e, a || [])).next());
            });
        },
    h =
        (this && this.__generator) ||
        function (n, o) {
            var i,
                r,
                a,
                s = {
                    label: 0,
                    sent: function () {
                        if (1 & a[0]) throw a[1];
                        return a[1];
                    },
                    trys: [],
                    ops: []
                },
                e = {next: t(0), throw: t(1), return: t(2)};
            return (
                "function" == typeof Symbol &&
                    (e[Symbol.iterator] = function () {
                        return this;
                    }),
                e
            );
            function t(t) {
                return function (e) {
                    return (function (t) {
                        {
                            if ((1, i)) throw new TypeError("Generator is already executing.");
                            for (; s; )
                                try {
                                    if (
                                        (0,
                                        (i = 1),
                                        r &&
                                            (a =
                                                2 & t[0]
                                                    ? r.return
                                                    : t[0]
                                                    ? r.throw || ((a = r.return) && a.call(r), 0)
                                                    : r.next) &&
                                            !(a = a.call(r, t[1])).done)
                                    )
                                        return a;
                                    switch (((r = 0), (t = a ? [2 & t[0], a.value] : t)[0])) {
                                        case 0:
                                        case 1:
                                            a = t;
                                            break;
                                        case 4:
                                            return s.label++, {value: t[1], done: !1};
                                        case 5:
                                            s.label++, (r = t[1]), (t = [0]);
                                            continue;
                                        case 7:
                                            (t = s.ops.pop()), s.trys.pop();
                                            continue;
                                        default:
                                            if (
                                                !(a = 0 < (a = s.trys).length && a[a.length - 1]) &&
                                                (6 === t[0] || 2 === t[0])
                                            ) {
                                                s = 0;
                                                continue;
                                            }
                                            if (3 === t[0] && (!a || (t[1] > a[0] && t[1] < a[3]))) {
                                                s.label = t[1];
                                                break;
                                            }
                                            if (6 === t[0] && s.label < a[1]) {
                                                (s.label = a[1]), (a = t);
                                                break;
                                            }
                                            if (a && s.label < a[2]) {
                                                (s.label = a[2]), s.ops.push(t);
                                                break;
                                            }
                                            a[2] && s.ops.pop(), s.trys.pop();
                                            continue;
                                    }
                                    t = o.call(n, s);
                                } catch (e) {
                                    (t = [6, e]), (r = 0);
                                } finally {
                                    i = a = 0;
                                }
                            if (5 & t[0]) throw t[1];
                            return {value: t[0] ? t[1] : void 0, done: !0};
                        }
                    })([t, e]);
                };
            }
        };
Object.defineProperty(n, "__esModule", {value: !0}), (n.VivoPlatform = void 0);
var d = e("index"),
    i = e("common"),
    f = e("const"),
    r = e("env"),
    s = e("events"),
    c = e("user-data"),
    l = e("platform-const"),
    e =
        ((a.prototype.string = function () {
            return l.PlatformCode.Vivo;
        }),
        (a.prototype.initSDK = function () {
            this.initWechatListener(), this.initCommonSetting(), this.initTga();
        }),
        (a.prototype.initTga = function () {
            var e;
            r.env.mode === r.EnvMode.PROD &&
                ((e = new ThinkingAnalyticsAPI(l.TgaConfig)).setSuperProperties({
                    ver: r.env.version,
                    platfrom: this.string(),
                    game: r.env.game
                }),
                e.init(),
                c.userData.setUid(e.getDistinctId()),
                (this.ta = e));
        }),
        (a.prototype.isSwitchedInitd = function () {
            return this.switchesInitd;
        }),
        (a.prototype.initWechatListener = function () {
            var n = this;
            qg.onShow(function (e) {
                var t = Date.now();
                console.log(l.LogTag, "on show", t),
                    s.platformEvent.emit({onShow: !0, isSharing: n.isSharing}),
                    c.userData.syncLaunchOption(e),
                    n.isSharing || n.reenter();
            }),
                qg.onHide(function () {
                    (n.onHideT = Date.now()),
                        console.log(l.LogTag, "on hide", n.onHideT),
                        s.platformEvent.emit({onHide: !0});
                }),
                qg.onError(function () {
                    r.env.mode, r.EnvMode.PROD;
                });
            var t = qg.getUpdateManager();
            t.onCheckForUpdate(function (e) {
                console.log(l.LogTag, "update checked, hasUpdate=" + e.hasUpdate);
            }),
                t.onUpdateFailed(function () {
                    console.log(l.LogTag, "update Failed");
                }),
                t.onUpdateReady(function () {
                    qg.showDialog({
                        title: "更新提示",
                        content: "新版本已经准备好，是否重启应用？",
                        success: function (e) {
                            e.confirm && t.applyUpdate();
                        }
                    });
                });
        }),
        (a.prototype.initCommonSetting = function () {
            var t = this;
            c.userData.syncLaunchOption(qg.getLaunchOptionsSync()),
                qg.getNetworkType({
                    success: function (e) {
                        c.userData.network = e.type;
                    }
                }),
                s.cheatEvent.on(function (e) {
                    "noAd" == e
                        ? ((t.noAd = !t.noAd), d.showToast("分享视频直接成功" + t.noAd))
                        : "switchVideo" == e
                        ? ((t.noVideo = !t.noVideo), d.showToast("强制没有视频" + t.noVideo))
                        : "clearStorage" == e && t.clearStorage();
                });
        }),
        (a.prototype.setAccountID = function () {
            r.env.mode, r.EnvMode.TEST;
        }),
        (a.prototype.login = function () {
            return o(this, void 0, Promise, function () {
                return h(this, function () {
                    return [2, null];
                });
            });
        }),
        (a.prototype.reenter = function () {}),
        (a.prototype.getStorage = function (e) {
            try {
                return JSON.parse(qg.getStorageSync(e));
            } catch (e) {
                return null;
            }
        }),
        (a.prototype.setStorage = function (e, t) {
            try {
                qg.setStorageSync(e, JSON.stringify(t));
            } catch (e) {}
        }),
        (a.prototype.clearStorage = function () {
            try {
                qg.clearStorageSync();
            } catch (e) {}
        }),
        (a.prototype.removeStorage = function (e) {
            try {
                qg.deleteStorage({key: e});
            } catch (e) {}
        }),
        (a.prototype.trackLogin = function () {
            throw new Error("Method not implemented.");
        }),
        (a.prototype.trackUserSet = function (e) {
            null != this.ta && this.ta.userSet(e);
        }),
        (a.prototype.trackUserSetOnce = function (e) {
            null != e && null != this.ta && this.ta.userSetOnce(e);
        }),
        (a.prototype.trackEvent = function (e, t) {
            null != this.ta &&
                ((t = p({runTime: c.userData.enterAt ? (Date.now() - c.userData.enterAt) / 1e3 : 0}, t)),
                this.ta.track(e, t));
        }),
        (a.prototype.getSeq = function () {
            throw new Error("Method not implemented.");
        }),
        (a.prototype.consumeSeq = function (t) {
            return o(this, void 0, Promise, function () {
                return h(this, function (e) {
                    switch (e.label) {
                        case 0:
                            return (
                                console.log(l.LogTag, "consume sequence", t),
                                t.sequenceInfo.type == l.STDSeqType.VIDEO ? [4, this.doWatchAD(t)] : [3, 2]
                            );
                        case 1:
                            return e.sent(), [3, 4];
                        case 2:
                            return [4, this.doShare(t)];
                        case 3:
                            e.sent(), (e.label = 4);
                        case 4:
                            return [2];
                    }
                });
            });
        }),
        (a.prototype.doWatchAD = function (a) {
            return o(this, void 0, Promise, function () {
                var i, r;
                return h(this, function () {
                    return this.noAd
                        ? [2]
                        : this.noVideo
                        ? [2, Promise.reject(l.VideoFailCode.NO_AD)]
                        : (s.adEvent.emit(f.AdEvent.VIDEO),
                          (i = this.uniqueVideoUnitId),
                          this.preloadVideo(i)
                              ? (this.showLoading(),
                                (r = this),
                                [
                                    2,
                                    new Promise(function (n, o) {
                                        r.videoAd.onClose(function e(t) {
                                            null != r.videoAd && r.videoAd.offClose(e),
                                                null != t && t.isEnded
                                                    ? (s.adEvent.emit(f.AdEvent.VIDEO_END),
                                                      r.trackEvent("video", {
                                                          step: "complete",
                                                          unit: i,
                                                          type: a.videoSource,
                                                          item: a.item
                                                      }),
                                                      c.userData.incVideoCnt(),
                                                      n())
                                                    : (s.adEvent.emit(f.AdEvent.VIDEO_END),
                                                      r.trackEvent("video", {
                                                          step: "cancel",
                                                          unit: i,
                                                          type: a.videoSource,
                                                          item: a.item
                                                      }),
                                                      o(l.VideoFailCode.CANCELED));
                                        }),
                                            r.videoAd
                                                .show()
                                                .then(function () {
                                                    r.trackEvent("video", {
                                                        step: "display",
                                                        success: !0,
                                                        unit: i,
                                                        type: a.videoSource,
                                                        item: a.item
                                                    });
                                                })
                                                .catch(function (e) {
                                                    console.log("<<<< video err: ", e),
                                                        r.trackEvent("video", {
                                                            step: "display",
                                                            success: !1,
                                                            unit: i,
                                                            type: a.videoSource,
                                                            item: a.item
                                                        }),
                                                        s.adEvent.emit(f.AdEvent.VIDEO_END),
                                                        r.videoAd.destroy(),
                                                        (r.videoAd = null),
                                                        o(l.VideoFailCode.NO_AD);
                                                })
                                                .then(function () {
                                                    r.hideLoading();
                                                });
                                    })
                                ])
                              : (s.adEvent.emit(f.AdEvent.VIDEO_END), [2, Promise.reject(l.VideoFailCode.NO_AD)]));
                });
            });
        }),
        (a.prototype.doShare = function () {
            return o(this, void 0, Promise, function () {
                return h(this, function () {
                    throw new Error("Method not implemented.");
                });
            });
        }),
        (a.prototype.canUse = function (e) {
            return 0 <= i.compareVersion(this.getSystemData().SDKVersion, e);
        }),
        (a.prototype.getSystemData = function () {
            if (null == this.systemInfoCache)
                try {
                    this.systemInfoCache = qg.getSystemInfoSync();
                } catch (e) {
                    return l.DefaultSystemInfo;
                }
            return this.systemInfoCache;
        }),
        (a.prototype.getSwitches = function () {
            return this.sdkSwitch;
        }),
        (a.prototype.vibrate = function (e) {
            e == l.VibrateType.SHORT
                ? qg.vibrateShort({success: function () {}, fail: function () {}})
                : e == l.VibrateType.LONG && qg.vibrateLong({success: function () {}, fail: function () {}});
        }),
        (a.prototype.preloadVideo = function (t) {
            t = this.uniqueVideoUnitId;
            var e = this.videoCheckedMap[t];
            if (e) return e;
            var n,
                o,
                i = this.videoCheckedLastT[t],
                r = Date.now();
            return (
                !e &&
                    (null == i || r - i >= l.SDKConfig.videoCoolTime) &&
                    (null == (o = this.videoAd) &&
                        ((n = this),
                        (o = qg.createRewardedVideoAd({adUnitId: this.uniqueVideoUnitId})),
                        (this.videoAd = o).onLoad(function () {
                            console.log("<<<< preload video success"),
                                (n.videoCheckedMap[t] = !0),
                                (n.videoCheckedLastT[t] = Date.now()),
                                n.trackEvent("video", {step: "pull", success: !0, unit: t});
                        }),
                        o.onError(function (e) {
                            console.log("<<<< preload video err: ", e),
                                (n.videoAd = null),
                                (n.videoCheckedMap[t] = !1),
                                (n.videoCheckedLastT[t] = Date.now()),
                                o.destroy(),
                                n.trackEvent("video", {step: "pull", success: !1, unit: t});
                        })),
                    null != o && o.load()),
                !1
            );
        }),
        (a.prototype.showModal = function (e) {
            return new Promise(function (t) {
                qg.showDialog(
                    p(p({}, e), {
                        success: function (e) {
                            e.confirm ? t(!0) : e.cancel && t(!1);
                        },
                        fail: function () {
                            t(!1);
                        }
                    })
                );
            });
        }),
        (a.prototype.refreshGame = function () {
            qg.exitApplication();
        }),
        (a.prototype.showLoading = function () {
            (this.isLoading = !0), qg.showLoading({title: "加载中", mask: !0});
        }),
        (a.prototype.hideLoading = function () {
            this.isLoading && (qg.hideLoading(), (this.isLoading = !1));
        }),
        (a.prototype.log = function (e) {
            for (var t = [], n = 1; n < arguments.length; n++) t[n - 1] = arguments[n];
        }),
        (a.prototype.getMenuBounding = function () {
            var e, t, n, o;
            return (
                null == this.menuBounding &&
                    (this.canUse("2.1.0")
                        ? ((e = qg.getMenuButtonBoundingClientRect()),
                          (o = this.getSystemData()),
                          (n = (t = cc.view.getFrameSize()).width / o.screenWidth),
                          (o = t.height / o.screenHeight),
                          (this.menuBounding = cc.rect(e.left * n, e.top * o, e.width * n, e.height * o)))
                        : (this.menuBounding = new cc.Rect(650, 0, 100, 50))),
                this.menuBounding
            );
        }),
        (a.prototype.createShareImage = function (l, u) {
            return o(this, void 0, Promise, function () {
                var n,
                    o,
                    i,
                    r,
                    a,
                    s,
                    c = this;
                return h(this, function () {
                    return f.ShareImage.has(l)
                        ? ((this.cacheCanvas = qg.createCanvas()),
                          this.cacheCanvas,
                          (this.cacheCanvas = qg.createCanvas()),
                          ((n = this.cacheCanvas).width = 400),
                          (n.height = 320),
                          (o = n.width),
                          (r = 320 * (i = o / 400)),
                          (a = n.getContext("2d")).clearRect(0, 0, o, r),
                          ((s = qg.createImage()).src = f.ShareImage.get(l)),
                          [
                              2,
                              new Promise(function (t) {
                                  (s.onload = function () {
                                      var e;
                                      a.clearRect(0, 0, o, r),
                                          a.drawImage(s, 0, 0, o, r),
                                          c.drawImage(l, a, p({scale: i, aimWidth: o}, u))
                                              ? ((e = n.toTempFilePathSync({
                                                    x: 0,
                                                    y: 0,
                                                    width: o,
                                                    height: r,
                                                    destWidth: o,
                                                    destHeight: r
                                                })),
                                                t(e))
                                              : t(null);
                                  }),
                                      (s.onerror = function (e) {
                                          console.error(e), d.showToast("网络错误~", 1500), t(null);
                                      });
                              })
                          ])
                        : [2, null];
                });
            });
        }),
        (a.prototype.drawImage = function () {
            return !1;
        }),
        (a.prototype.preloadInterstitialAD = function () {}),
        (a.prototype.showInterstitialAD = function () {
            return o(this, void 0, Promise, function () {
                return h(this, function () {
                    return [2];
                });
            });
        }),
        (a.prototype.canShowBanner = function () {
            return !1;
        }),
        (a.prototype.getBannerSize = function () {
            return new cc.Size(0, 0);
        }),
        (a.prototype.showBanner = function () {
            cc.log("QQ does not support banner");
        }),
        (a.prototype.hideBanner = function () {
            cc.log("QQ does not support banner");
        }),
        (a.prototype.getSubscribeCnt = function () {
            return o(this, void 0, Promise, function () {
                return h(this, function () {
                    return [2, 0];
                });
            });
        }),
        (a.prototype.subscribe = function (e) {
            for (var t = [], n = 1; n < arguments.length; n++) t[n - 1] = arguments[n];
            return o(this, void 0, Promise, function () {
                return h(this, function () {
                    throw new Error("Method not implemented.");
                });
            });
        }),
        (a.prototype.startVideoRecord = function () {}),
        (a.prototype.pauseVideoRecord = function () {}),
        (a.prototype.resumeVideoRecord = function () {}),
        (a.prototype.stopVideoRecord = function () {}),
        (a.prototype.hasVideoRecord = function () {
            return !1;
        }),
        (a.prototype.shareVideoRecord = function () {}),
        (a.prototype.uploadAdEvent = function () {}),
        (a.prototype.uploadAdEvent_Addict = function () {}),
        (a.prototype.addShortcut = function () {
            qg.hasShortcutInstalled({
                success: function (e) {
                    e
                        ? (console.log("已创建"), d.platform.trackEvent("clickAddDeck", {bool: !1}))
                        : (console.log("未创建"),
                          qg.installShortcut({
                              message: "随时随地秒开即玩，一键添加不迷路！",
                              success: function () {
                                  console.log("创建成功"), d.platform.trackEvent("clickAddDeck", {bool: !0});
                              },
                              fail: function () {
                                  console.log("创建失败"), d.platform.trackEvent("clickAddDeck", {bool: !1});
                              },
                              complete: function () {
                                  console.log("取消创建"), d.platform.trackEvent("clickAddDeck", {bool: !1});
                              }
                          }));
                }
            });
        }),
        a);
function a() {
    (this.isSharing = !1),
        (this.sdkSwitch = l.DefaultSDKSwitch),
        (this.videoCheckedMap = {}),
        (this.videoCheckedLastT = {}),
        (this.uniqueVideoUnitId = "dc8bc3ac72254460852302e6d0ae6bff"),
        (this.isLoading = !1),
        (this.isLoggedIn = !1),
        (this.onHideT = 0),
        (this.noAd = !1),
        (this.noVideo = !1),
        (this.lastInterAdShowT = 0),
        (this.switchesInitd = !1),
        (this.ta = null);
}
n.VivoPlatform = e;
